package iec104_apdu

import (
	"encoding/binary"
)

// parseBigEndianUint16 转换大端Uint16
func ParseLittleEndianUInt16(i uint16) []byte {
	bytes := make([]byte, 2, 2)
	binary.LittleEndian.PutUint16(bytes, i)
	return bytes
}

// ParseBigEndianUint16 转换大端Uint16
func ParseBigEndianUInt16(i uint16) []byte {
	bytes := make([]byte, 2, 2)
	binary.BigEndian.PutUint16(bytes, i)
	return bytes
}

// convertBytes 转换 成完整的报文数据发磅发送数据
func ConvertIec104Bytes(data []byte) []byte {
	sendData := make([]byte, 0, 0)
	iBytes := ParseBigEndianUInt16(uint16(len(data)))
	sendData = append(sendData, StartFrame)
	sendData = append(sendData, iBytes[1])
	sendData = append(sendData, data...)
	return sendData
}

func Convert4BytesToSlice(b [4]byte) []byte {
	return []byte{b[0], b[1], b[2], b[3]}
}

func ConvertSliceTo4Bytes(b []byte) [4]byte {
	return [4]byte{b[0], b[1], b[2], b[3]}
}
